package org.lili.methodchain;

import org.lili.semanticmodel.Edge;
import org.lili.semanticmodel.Vertex;

/**
 * @author lili
 * @description EdgeBuilder which is the expression builder for populating the Edge model.
 * @create 2018-04-22 下午3:37
 * @since
 **/
public class EdgeBuilder {

    Edge edge;

    //Keep a back reference to the Graph Builder.
    GraphBuilder graphBuilder;

    public EdgeBuilder(GraphBuilder graphBuilder) {
        this.graphBuilder = graphBuilder;
        edge = new Edge();
    }

    public EdgeBuilder from(String lbl) {
        Vertex v = new Vertex(lbl);
        edge.setFromVertex(v);
        graphBuilder.getGraph().addVertice(v);
        return this;
    }

    public EdgeBuilder to(String lbl) {
        Vertex v = new Vertex(lbl);
        edge.setToVertex(v);
        graphBuilder.getGraph().addVertice(v);
        return this;
    }

    public GraphBuilder weight(Double d) {
        edge.setWeight(d);
        return graphBuilder;
    }
}
